package indi.lqzhi.basic.tools.bean;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * 包装类型
 * 主要用于BusUtils传递的对象必须要要为Object,byte[]无法传递，导致SocketClient无法使用
 */
public class WrapObject<T> implements Parcelable {

    private T t;

    public WrapObject() {
    }

    public WrapObject(T t) {
        this.t = t;
    }

    protected WrapObject(Parcel in) {
        t = (T) in.readValue(t.getClass().getClassLoader());
    }

    public static final Creator<WrapObject<?>> CREATOR = new Creator<WrapObject<?>>() {
        @Override
        public WrapObject<?> createFromParcel(Parcel in) {
            return new WrapObject<>(in);
        }

        @Override
        public WrapObject<?>[] newArray(int size) {
            return new WrapObject[size];
        }
    };

    public T get() {
        return t;
    }

    public void set(T t) {
        this.t = t;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeValue(t);
    }
}
